package cn.xshi.log.web;

import cn.xshi.log.form.LogStartStopForm;
import cn.xshi.log.model.LogStartStop;
import cn.xshi.log.service.LogStartStopService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.util.StringUtil;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @Desc 服务器启动与关闭日志
* @Author 邓纯杰
* @CreateTime 2022-08-24 12:28:59
*/
@RestController
@RequestMapping("/logStartStop")
@Api(value = "服务器启动与关闭日志API",tags = "服务器启动与关闭日志API",description = "服务器启动与关闭日志")
public class LogStartStopController extends BaseAction{

	@Resource
	private LogStartStopService logStartStopService;

	/**
	 * 查询并分页
	 * @param logStartStopForm
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@ApiOperation(value="查询并分页", notes="查询并分页")
	@GetMapping(value="/list")
	@Auth(value = "/logStartStop/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BasePage<List<LogStartStop>> getLogStartStopListByCondition(LogStartStopForm logStartStopForm, Integer pageNo, Integer pageSize){
		commonHPagerByPageNo(pageNo,pageSize);
		List<LogStartStop> logStartStopList = logStartStopService.getLogStartStopListByCondition(logStartStopForm);
		PageInfo<LogStartStop> page = new PageInfo<LogStartStop>(logStartStopList);
		return outPageBootByPageNo(page,pageNo,pageSize);
	}

	/**
	* 查询单条记录
	* @param id 
	*/
	@ApiOperation(value="查询单条记录", notes="查询单条记录")
	@GetMapping(value="/get/{id}")
	@Auth(value = "/logStartStop/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	public BaseResult<LogStartStop> getLogStartStopById(@PathVariable("id")String id){
		LogStartStop logStartStop = logStartStopService.getLogStartStopById(id);
		return outDataStr(logStartStop);
	}

	/**
	* 添加
	* @param logStartStop 
	*/
	@ApiOperation(value="添加", notes="添加")
	@PostMapping(value="/add")
	@Auth(value = "/logStartStop/add",authenticationType = Auth.AuthorizationType.NOT_REQUIRED_LOGIN)
	public BaseResult addLogStartStop(@RequestBody LogStartStop logStartStop){
		int i = 0;
		if(null != logStartStop){
			logStartStop.setId(toUUID());
			i=logStartStopService.addLogStartStop(logStartStop);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
	
	/**
	* 删除
	* @param id 
	*/
	@ApiOperation(value="删除", notes="删除")
	@DeleteMapping(value="/delete")
	public BaseResult delLogStartStop(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=logStartStopService.delLogStartStop(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}
}
